import 'package:mahjong/entity/MessageContext.dart';
import 'package:mahjong/notify/CurrentUserInfo.dart';
import 'package:mahjong/util/AudioPlayUtil.dart';
import 'package:provider/provider.dart';
import 'package:mahjong/entity/card/MahjongUserSwapCard.dart';

import 'AbstractMessageHandler.dart';
import 'package:mahjong/const/MahjongConst.dart';

class MessageCardExchange extends AbstractMessageHandler {
  void doMessage(MessageContext message) {
    exchangeCardStreamController.add(message);
    MahjongUserSwapCard userSwapCard =
        MahjongUserSwapCard.fromJson(message.body);
    diskPartUserProvider.forEach((key, value) {
      // 如果用户相同的话 添加卡牌
      if (value.userId == message.userId) {
        value.swapSuccess(userSwapCard, null);
      } else {
        // 其它用户需要修改手牌数量
        if (value.banker) {
          value.swapSuccess(null, CardEnum.BANKER_COUNT);
        } else {
          value.swapSuccess(null, CardEnum.LEISURE_COUNT);
        }
      }
    });
  }
}
